package club.gggd.qqrobot.boot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @Description 项目启动检查所需文件夹是否创建
 * @Author srx
 * @date 2022/9/6 16:38
 */
@Component
@Slf4j
public class CheckFolder implements ApplicationRunner {

    @Value("${path.strategy}")
    private String strategyPath;

    @Value("${path.random-picture.path}")
    private String randomPicturePath;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 角色攻略文件夹
        File strategyFile = new File(strategyPath);
        if(!strategyFile.exists()){
            log.info("创建文件夹：{}", strategyPath);
            strategyFile.mkdirs();
        }

        // 随机图片文件夹
        File randomPictureFile = new File(randomPicturePath);
        if(!randomPictureFile.exists()){
            log.info("创建文件夹：{}", randomPicturePath);
            randomPictureFile.mkdirs();
        }

    }
}
